000100******************************************************************
000200*PROGRAM : Add course to the ISAM FILE                           *
000300*AUTHOR  : Minh-Tuan Ta                                          *
000400******************************************************************
000500 IDENTIFICATION DIVISION.
000600 PROGRAM-ID. CRS-A.
000700 ENVIRONMENT DIVISION.
000800     SELECT IOFILE       ASSIGN TO "CRSMST.DAT"
000900                         ORGANIZATION  IS INDEXED
001000                         ACCESS        IS RANDOM
001100                         RECORD KEY    IS OUT-CRS-ID
001200                         FILE STATUS   IS WS-STAT.
001300
001400 DATA DIVISION.
001500 FILE SECTION.
001600 FD  IOFILE.
001700 01  OUT-REC.
001800     03  OUT-CRS-ID      PIC X(8).
001900     03  OUT-CRS-NAME    PIC X(34).
002000     03  OUT-CRS-H       PIC 99.
002100     03  OUT-CRS-A       PIC X.
002200
002300 WORKING-STORAGE SECTION.
002400 01  WS-STAT             PIC XX.
002500 01  WS-EOF              PIC X VALUE 'N'.
002600 01  WS-CRS-ID           PIC X(8).
002700 01  WS-CRS-SUBJECT      PIC X(4).
002800 01  WS-CRS-NO           PIC X(4).
002900 01  WS-CRS-NAME         PIC X(30).
003000 01  WS-CRS-H            PIC 9(2).
003100 01  WS-CRS-A            PIC X.
003200 01  WS-DATE.
003300     03  WS-YEAR         PIC 99.
003400     03  WS-MONTH        PIC 99.
003500     03  WS-DAY          PIC 99.
003600 01  WS-ERR              PIC X VALUE 'N'.
003700 01  WS-CONT             PIC X VALUE 'Y'.
003800 01  WS-ADD              PIC X VALUE 'N'.
003900
004000 SCREEN SECTION.
004100 01  INPUT-SCRN.
004200         05  BLANK SCREEN.
004300         05  LINE 1  COL 01  VALUE "ADD COURSE".
004400         05          COL 73  PIC 9(2) FROM WS-MONTH.
004500         05          COL 75  VALUE "/".
004600         05          COL 76  PIC 9(2) FROM WS-DAY.
004700         05          COL 78  VALUE "/".
004800         05          COL 79  PIC 9(2) FROM WS-YEAR.
004900         05  LINE 2  COL 37  VALUE "ADD COURSE".
005000         05  INPUT-CRS-SUBJECT-SCRN.
005100             10  LINE 4  COL 20  VALUE "COURSE SUBJECT".
005200             10          COL 40  PIC X(4) TO WS-CRS-SUBJECT.
005300         05  INPUT-CRS-NO-SCRN.
005400             10  LINE 5  COL 20  VALUE "COURSE NUMBER".
005500             10          COL 40  PIC X(4) TO WS-CRS-NO.
005600         05  INPUT-CRS-NAME-SCRN.
005700             10  LINE 6  COL 20  VALUE "COURSE NAME".
005800             10          COL 40  PIC X(30) TO WS-CRS-NAME.
005900         05  INPUT-CRS-H-SCRN.
006000             10  LINE 7  COL 20  VALUE "CREDIT HOURS".
006100             10          COL 40  PIC 9(2) TO WS-CRS-H AUTO.
006200         05  INPUT-CRS-A-SCRN.
006300             10  LINE 8  COL 20  VALUE "ACTIVATE (Y/N)?".
006400             10          COL 40  PIC X TO WS-CRS-A AUTO.
006500         05  LINE 11 COL 34  VALUE "(ENTER XXX TO EXIT)".
006600 01  ERROR-SCRN.
006700     03  BLANK SCREEN.
006800     03  LINE 12 COL 32 VALUE "ERROR ADDING RECORD".
006900     03  LINE 14 COL 32 VALUE "FILE STATUS:".
007000     03          COL 46 PIC XX FROM WS-STAT.
007100     03  LINE 15 COL 32 VALUE "RECORD KEY:".
007200     03          COL 46 PIC X(8) FROM OUT-CRS-ID.
007300     03  LINE 16 COL 32 VALUE "CONTINUE(Y/N)?".
007400     03          COL 47 PIC X TO WS-CONT AUTO.
007500
007600 01  SUCCESS-SCRN.
007700     03  BLANK SCREEN.
007800     03  LINE 12 COL 32 VALUE "RECORD ADDED SUCCESSFULLY".
007900     03  LINE 13 COL 32 VALUE "RECORD INFORMATION:".
008000     03  LINE 14 COL 32 VALUE "COURSE ID".
008100     03          COL 46 PIC X(8) FROM OUT-CRS-ID.
008200     03  LINE 15 COL 32 VALUE "COURSE NAME".
008300     03          COL 46 PIC X(30) FROM OUT-CRS-NAME.
008400     03  LINE 16 COL 32 VALUE "COURSE HOURS".
008500     03          COL 46 PIC 9(2) FROM OUT-CRS-H.
008600     03  LINE 17 COL 32 VALUE "ACTIVATE?".
008700     03          COL 46 PIC X FROM OUT-CRS-A.
008800     03  LINE 18 COL 32 VALUE "CONTINUE(Y/N)?".
008900     03          COL 47 PIC X TO WS-CONT AUTO.
009000
009100 01  ADD-REC-SCRN.
009200     03  BLANK SCREEN.
009300     03  LINE 4  COL 20  VALUE "COURSE SUBJECT".
009400     03          COL 40  PIC X(4) FROM WS-CRS-SUBJECT.
009500     03  LINE 5  COL 20  VALUE "COURSE NUMBER".
009600     03          COL 40  PIC X(4) FROM WS-CRS-NO.
009700     03  LINE 6  COL 20  VALUE "COURSE NAME".
009800     03          COL 40  PIC X(30) FROM WS-CRS-NAME.
009900     03  LINE 7  COL 20  VALUE "CREDIT HOURS".
010000     03          COL 40  PIC 9(2) FROM WS-CRS-H.
010100     03  LINE 8  COL 20  VALUE "ACTIVATE (Y/N)?".
010200     03          COL 40  PIC X FROM WS-CRS-A.
010300     03  LINE 9  COL 32 VALUE "DO YOU WANT TO ADD RECORD(Y/N)?".
010400     03          COL 65 PIC X TO WS-ADD AUTO.
010500
010600 01  CONTINUE-SCRN.
010700     03  BLANK SCREEN.
010800     03  LINE 9  COL 32 VALUE "DO YOU WANT TO CONTINUE(Y/N)?".
010900     03          COL 64 PIC X TO WS-CONT AUTO.
011000
011100
011200
011300
011400 PROCEDURE DIVISION.
011500 100-MAIN.
011600     ACCEPT WS-DATE FROM DATE
011700     OPEN I-O IOFILE.
011800
011900     MOVE SPACES TO WS-CRS-ID
012000     MOVE SPACES TO WS-CRS-NAME
012100     MOVE ZEROS TO WS-CRS-H
012200     MOVE SPACES TO WS-CRS-A
012300     MOVE 'Y' TO WS-CONT
012400
012500     DISPLAY INPUT-SCRN
012600     ACCEPT INPUT-CRS-SUBJECT-SCRN
012700
012800     PERFORM UNTIL WS-CRS-SUBJECT = 'XXX' OR WS-CONT = 'N'
012900
013000         ACCEPT INPUT-CRS-NO-SCRN
013100
013200         STRING WS-CRS-SUBJECT DELIMITED BY SIZE
013300         WS-CRS-NO DELIMITED BY SIZE
013400         INTO WS-CRS-ID
013500
013600         ACCEPT INPUT-CRS-NAME-SCRN
013700         ACCEPT INPUT-CRS-H-SCRN
013800         ACCEPT INPUT-CRS-A-SCRN
013900
014000         MOVE WS-CRS-ID      TO OUT-CRS-ID
014100         MOVE WS-CRS-NAME    TO OUT-CRS-NAME
014200         MOVE WS-CRS-H       TO OUT-CRS-H
014300         MOVE WS-CRS-A       TO OUT-CRS-A
014400
014500         MOVE 'N' TO WS-ADD
014600
014700         DISPLAY ADD-REC-SCRN
014800         ACCEPT ADD-REC-SCRN
014900
015000         IF NOT WS-ADD = 'N'
015100
015200             MOVE 'N' TO WS-ERR
015300
015400             IF WS-CRS-ID = SPACES OR WS-CRS-NAME = SPACES
015500                 OR WS-CRS-H = SPACES OR WS-CRS-A = SPACES
015600                 MOVE 'Y' TO WS-ERR
015700             END-IF
015800
015900             IF NOT WS-ERR = 'Y'
016000
016100                 MOVE 'N' TO WS-ERR
016200
016300                 WRITE OUT-REC
016400                     INVALID KEY MOVE 'Y' TO WS-ERR
016500                 END-WRITE
016600
016700                 IF WS-ERR = 'Y'
016800                     DISPLAY ERROR-SCRN
016900                     ACCEPT ERROR-SCRN
017000                 ELSE
017100                     DISPLAY SUCCESS-SCRN
017200                     ACCEPT SUCCESS-SCRN
017300                 END-IF
017400             ELSE
017500                 DISPLAY ERROR-SCRN
017600                 ACCEPT ERROR-SCRN
017700             END-IF
017800         ELSE
017900             DISPLAY CONTINUE-SCRN
018000             ACCEPT CONTINUE-SCRN
018100         END-IF
018200
018300         IF WS-CONT = 'Y'
018400             DISPLAY INPUT-SCRN
018500             MOVE SPACES TO WS-CRS-ID
018600             MOVE SPACES TO WS-CRS-NAME
018700             MOVE ZEROS TO WS-CRS-H
018800             MOVE SPACES TO WS-CRS-A
018900             ACCEPT INPUT-CRS-SUBJECT-SCRN
019000         END-IF
019100     END-PERFORM
019200     CLOSE IOFILE
019300     EXIT PROGRAM.
